<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>地图页</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">

    <!--标准mui.css-->
    <link rel="stylesheet" href="__PUBLIC__/css/mui.min.css">
    <!--App自定义的css-->
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/app.css" />
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    <style type="text/css">
        body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=IAwxRMWcGZiNzohAyxcImHbZEGM4SXsH"></script>
</head>
<body>
<header class="mui-bar mui-bar-nav">
    <a onclick="dump('{:U('index')}')" class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
    <script>
        //url跳转
        function dump(url) {
            location.href=url
        }
    </script>
    <h1 class="mui-title">地图模式</h1>
    <a  href="{:U('lists')}" class="mui-qiehuan-icon  mui-pull-right"></a>
</header>
<html>
<body>
<div id="allmap"></div>
<foreach name="data" item="vo">
   <!-- 官方仓-->
    <if condition="$vo[Belone] eq 'E'">
    <input type="hidden" class="data" value="{$vo.Name}" url="{:U('detail',array('id'=>$vo['StoreID']))}" Lng="{$vo.Lng}" Lat="{$vo.Lat}">
    <else/>
    <input type="hidden" class="datas" value="{$vo.Name}" url="{:U('detail',array('id'=>$vo['StoreID']))}" Lng="{$vo.Lng}" Lat="{$vo.Lat}">
    </if>
</foreach>
</body>
</html>
<script>
    opts = {

    };
    icon = new BMap.Icon('point.png', new BMap.Size(25, 25), {
    });
    map = new BMap.Map("allmap");
    var geolocation = new BMap.Geolocation();
    geolocation.getCurrentPosition(function (r) {
        if (this.getStatus() == BMAP_STATUS_SUCCESS) {
            //alert('您的位置：' + r.point.lng + ',' + r.point.lat);
            lat = r.point.lat;
            lon = r.point.lng;
            //转换为百度坐标
            var po = new BMap.Point(lon, lat);
            //生成地图
            map.centerAndZoom(po,14);
            //仓库标注
            $(".data").each(function(){

                var marker = new BMap.Marker(new BMap.Point($(this).attr('Lng'),$(this).attr('Lat')));  // 创建标注
                var content = $(this).val()
                map.addOverlay(marker);               // 将标注添加到地图中
                addClickHandler('<a href="'+$(this).attr('url')+'">'+content+'</a>',marker);
            });
            //加盟仓标注
            $(".datas").each(function(){

                var marker = new BMap.Marker(new BMap.Point($(this).attr('Lng'),$(this).attr('Lat')), {icon: icon});
                var content = $(this).val()
                map.addOverlay(marker);
                addClickHandler('<a href="'+$(this).attr('url')+'">'+content+'</a>',marker);
            });
        }
        else {
            alert('百度地图地位失败！' + this.getStatus());
        }
    }, { enableHighAccuracy: true })
    function addClickHandler(content,marker){
        marker.addEventListener("click",function(e){
            openInfo(content,e)}
        );
    }
    function openInfo(content,e){0
        var p = e.target;
        var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
        var infoWindow = new BMap.InfoWindow(content,opts);  // 创建信息窗口对象
        map.openInfoWindow(infoWindow,point); //开启信息窗口
    }
</script>
